package com.nf.action;

import com.nf.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController//没有这个注解可以手动配置TestAction实现类的bean
public class TestAction {

    @Autowired
    //因为TestServiceImp2实现类使用了@Service注解了 自动配置了bean 所以可以@Autowired注解实例
    @Qualifier("testServiceImpl2")//当name不同时，type有两个相同的类型时 @Qualifier指定使用那个实现类。
    private TestService testServiceImpl2;

//    public void setTestService(TestService testService) {
//        System.out.println("第2步：在TestAction中注入一个service");
//        this.testService = testService;
//    }

    public TestAction(){
        System.out.println("第1步：TestAction 创建了实例:"+this);
    }

    @RequestMapping("/abcd")
    public String aa(){
        System.out.println("testService:"+testServiceImpl2);
        System.out.println("第3步：使用TestAction.aa（）");
        return "t1";
    }

    @RequestMapping("/bbb")
    public String bb(){
        System.out.println("testService:"+testServiceImpl2);
        System.out.println(testServiceImpl2.kk());
        testServiceImpl2.kk();
        return "t1";
    }

    @RequestMapping("/ccc")
    public String cc(){
        testServiceImpl2.CC();
        return "t1";
    }

    @RequestMapping("/ddd")
    public String dd(){
        testServiceImpl2.转账();
        return "t1";
    }
}
